package leetcode

//https://leetcode.cn/problems/intersection-of-two-arrays/description/
class Solution_349 {
    //方法二，
    fun intersection(nums1: IntArray, nums2: IntArray): IntArray {
        val result = HashSet<Int>()
        val set1 = nums1.toSet()
        val set2 = nums2.toSet()
        for (i in set1) {
            if (set2.contains(i)) result.add(i)
        }
        return result.toIntArray()
    }
}